<?php
/* @var $this UserController */
/* @var $model User */

$this->breadcrumbs=array(
	Yii::t('app', 'Message')=>array('index'),
	Yii::t('app', 'Search'),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-form form').submit(function(){
	$('#message-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<div class="page-header">
	<div class="page-title"><h3><?php echo Yii::t('app', 'Message Search' ) ?></h3></div>
</div>

<h1></h1>

<div class="search-form">
<?php $this->renderPartial('search/_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php $sum = $model->getSearchSummary() ?>
<table class="table table-striped table-condensed table-nobor" id="tabSum">
	<tr>
		<td><strong><?php echo Yii::t('app', 'User' ) ?></strong></td>
		<td></td>
		<td class="span2"><strong><?php echo Yii::t('app', 'Operator' ) ?></strong></td>
		<td></td>
	</tr>
	<tr>
		<td><?php echo Yii::t('app', 'Message transmission number' ) ?>:</td>
		<td><?php echo $sum['user_send'] ?></td>
		<td><?php echo Yii::t('app', 'Message transmission number' ) ?>:</td>
		<td><?php echo $sum['opr_send'] ?></td>
	</tr>
	<tr>
		<td><?php echo Yii::t('app', 'Number of received messages' ) ?>:</td>
		<td><?php echo $sum['user_recv'] ?></td>
		<td><?php echo Yii::t('app', 'Number of received messages' ) ?>:</td>
		<td><?php echo $sum['opr_recv'] ?></td>
	</tr>
</table>

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'message-grid',
	'dataProvider'=>$model->search(),
	'columns'=>array(
		array(
			'class'=>'CButtonColumn',
			'template'=>'{view_user}',
			'buttons'=>array(
				'view_user' => array(
					'label'=>Yii::t('app', 'View Detail'),
					'url'=>'Yii::app()->createAbsoluteUrl("admin/user/update", array("id"=>$data->sender->id))',
					'options'=>array('class'=>'btn btn-info'),
				)
			),
			'headerHtmlOptions'=>array('class'=>'span2'),
		),
		array(
			'header' => Yii::t('app', 'Nickname'),
			'value' => '$data->sender->nickname',
		),
		array(
			'header' => Yii::t('app', 'Profile ID'),
			'value' => '$data->sender->profile_id',
		),
		'created_time:time',
		// actions
		array(
			'header'=>Yii::t('app', 'View History'),
			'class'=>'CButtonColumn',
			'template'=>'{view_msg}',
			'buttons'=>array(
				'view_msg' => array(
					'label'=>Yii::t('app', 'View History'),
					'url'=>'Yii::app()->createAbsoluteUrl("admin/message/history", array("id"=>$data->sender->id))',
					'options'=>array('class'=>'btn btn-info'),
				)
			),
			'headerHtmlOptions'=>array('class'=>'span4'),
		),
	),
	'itemsCssClass'=>'table table-bordered table-hover',
	'cssFile'=>false,
	'afterAjaxUpdate' => 'updateSummary',
)); ?>

<script>
function updateSummary(id,data) {
	$('#tabSum').html($(data).find('#tabSum').html());
}
</script>